package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * 简历控制器
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {
    public static final String LISTPAGE="/list.jsp";

    @Autowired
    private ResumeService resumeService;

    @RequestMapping(value = "/list",method={RequestMethod.GET})
    public String list( ModelMap modelMap)  {
        List<Resume> resumes = resumeService.findAll();
        modelMap.addAttribute("resumes", resumes);
        return LISTPAGE;
    }

    /**
     * 保持或修改
     * @param resume
     * @return
     */
    @RequestMapping(value = "/save",method={RequestMethod.POST})
    public String save( Resume resume)  {
        this.resumeService.save(resume);
        return "redirect:/resume/list";
    }

    /**
     * 跳转编辑页面
     * @param id
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "/toEdit",method={RequestMethod.GET})
    public String toEdit( Long id, ModelMap modelMap)  {
        Resume  resume = this.resumeService.get(id);
        modelMap.addAttribute("resume",resume);
        return "/resume-add.jsp";
    }

    @RequestMapping(value = "/del",method={RequestMethod.GET})
    public String delete( Long id)  {
        this.resumeService.delete(id);
        return "redirect:/resume/list";
    }



}
